//
//  CMDBUserInfoBean.swift
//  CMDB
//
//  Created by 王磊 on 17/4/5.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

public class CMDBUserInfoBean: NSObject {
    
    var uid: String = "" /* uid 唯一标识 */
    
    var token: String = "" /* token 与请求有关 */
    
    var phone: String = "" /* 手机号*/
    
    var name: String = "" /* 姓名 */
    
    var useNames: String = "" /* 曾用名['陈港生','房XX'] */
    
    var tempUseNames: Array<String> {
        
        guard !useNames.isEmpty else {
            
            return []
        }
        
        return CMDBUserInfoBean.castStringToStringArr(useNames)
    }
    
    var icon: String = "" /* 头像 */
    
    var gender: String = "" /* 性别 */
    
    var letter: String = "" /* 名字首字母  如果没有头像 就用首个字符代替 */
    
    var genderType: CMDBGenderType {
        
        guard !gender.isEmpty else {
            
            return CMDBGenderType.UnKnown
        }
        return CMDBGenderType(string: gender)
    }
    var associate: String = "" /* 是否关联了 */
    
    var isAssociate: Bool {
        return associate == "1" ? true : false
    }
    var type: String = "" /* 用户类型  0 普通用户  1 官方用户 */
    
    var userType: CMDBUserType {
        
        guard !type.isEmpty else {
            
            return CMDBUserType.UnKnown
        }
        return CMDBUserType(string: type)
    }
    
    var followCount: String = ""
    
    var fansCount: String = ""
    
    var friendCount: String = ""
    
    var bgUrl: String = ""
    
    var atags: Array<CMDBAtibuteTagBean>?
    
    var iscommit: Bool = false
}
extension CMDBUserInfoBean: DictModelProtocol {
    
    public static func customClassMapping() -> [String : String]? {
        
        return ["atags":"CMDBAtibuteTagBean"]
    }
}
extension CMDBUserInfoBean {
    
    static func castStringToStringArr(str: String) -> Array<String> {
        
        let jsonData = str.dataUsingEncoding(NSUTF8StringEncoding)
        
        guard let json = jsonData else {
            
            return []
        }
        
        let jsonArr = try? NSJSONSerialization.JSONObjectWithData(json, options: NSJSONReadingOptions(rawValue: NSJSONReadingOptions.MutableContainers.rawValue))
        
        return jsonArr as! Array<String>
    }
    
}
